<template>
  <div class="relative w-full pb40">
    <SearchCom :searchList="searchList" @search="handleSearch" @reset="handleReset" />
    <el-table
      :data="tableData"
      style="width: 100%"
      class="cover-table mt12"
      border
      v-loading="loading"
    >
      <el-table-column :label="$t('sellerAnnualFee.table.序号')" width="80">
        <template #default="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="id" :label="$t('sellerAnnualFee.table.商户ID')" />
      <el-table-column :prop="'name' + locale" :label="$t('sellerAnnualFee.table.店铺名称')" />
      <el-table-column prop="code" :label="$t('sellerAnnualFee.table.店主账号')" />
      <el-table-column prop="settleContact" :label="$t('sellerAnnualFee.table.联系人')" />
      <el-table-column prop="settlePhone" :label="$t('sellerAnnualFee.table.联系人电话')" />
      <el-table-column prop="validTimeEnd" :label="$t('sellerAnnualFee.table.到期时间')">
        <template #default="scope">
          <span>{{ moment(scope.row.validTimeEnd).format("YYYY-MM-DD") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <div class="flex justify-end mt24 absolute bottom-0 right-0">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <EditDia v-model="editDiaVisible"></EditDia>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import EditDia from "./editDia.vue";
import Api from "@/config/api/api";
import { useI18n } from "vue-i18n";
import moment from "moment";
import SearchCom from "@/components/SearchCom.vue";
const { locale, t } = useI18n();

const searchList = [
  {
    label: t("sellerAnnualFee.table.商户ID"),
    key: "id",
    type: "input",
  },
  {
    label: t("sellerAnnualFee.table.店铺名称"),
    key: "name",
    type: "input",
  },
  {
    label: t("sellerAnnualFee.table.店主账号"),
    key: "code",
    type: "input",
  },
  {
    label: t("sellerAnnualFee.table.联系人"),
    key: "settleContact",
    type: "input",
  },
  {
    label: t("sellerAnnualFee.table.联系人电话"),
    key: "settlePhone",
    type: "input",
  },
];

const props = defineProps({
  type: {
    type: String,
    default: "1",
  },
});
const editDiaVisible = ref(false);
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const tableData = ref([]);
const loading = ref(false);
const handleSizeChange = (size) => {
  pageSize.value = size;
  currentPage.value = 1;
  getDataList();
};
const handleCurrentChange = (page) => {
  currentPage.value = page;
  getDataList();
};
const handleSearch = (params) => {
  currentPage.value = 1;
  getDataList(params);
};
const handleReset = () => {
  currentPage.value = 1;
  getDataList();
};
const getDataList = (params={}) => {
  loading.value = true;
  Api.getTenantList({
    page: currentPage.value - 1,
    size: pageSize.value,
    status: -2,
    ...params,
    ["name" + locale.value]: params?.name,
  }).then((res) => {
    tableData.value = res.data.content || [];
    total.value = Number(res.data.totalElements || 0);
  }).finally(()=>{
    loading.value = false;
  });
};

onMounted(() => {
  getDataList();
});
</script>

<style lang="scss" scoped>
.addBtn {
  height: 28px;
  margin-left: 10px;
  padding: 0 7px;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.split {
  width: 1px;
  height: 12px;
  background: #ddd;
  margin: 0 5px;
}
</style>
